$(function(){
        var c_link_url=encodeURIComponent(window.location.href);
        console.log(c_link_url);
        /**
         *获取url中指定字符变量的值
         */
        var shopId=SYS_GLOBAL_CONFIG.getQueryString("shopId");
        var userId;
        var user_id;
        if(window.localStorage){
            user_id=localStorage.userId;
        }else{
            user_id=SYS_GLOBAL_CONFIG.getQueryString("userId");
            alert("请打开浏览器cookie功能,或者更换浏览器");
            console.log("当前浏览器不支持本地localStorage");
        }
        if(user_id!=undefined && user_id!="" && user_id!=null){
            userId=parseInt(user_id);
        }
        var url=SYS_GLOBAL_CONFIG.shaUrl,
            async=true,
            type="post";
        var JsonData={
            "data":{"shopId": shopId,"userId":userId},
            "version":"1.0",
            "code":"getShopDetail"
        };
        var requestData=JSON.stringify(JsonData); 
        var requestData1="";
        var requestData6="";
        
        getData(url,requestData,handdle_func_succ,handdle_func_err,async,type);        
        /**
         *async默认为true, 异步加载
         */
        function getData(url,requestData,handdle_func_succ,handdle_func_err,async,type){
            console.log("请求参数"+requestData);
            $.ajax({
                url:url,
                type:type,
                datatype:"json",       
                async:async,
                contentType:"application/json",
                data:requestData,
                success:function(data){
                    handdle_func_succ(data);
                },
                error:function(msg){
                    handdle_func_err(msg);
                }   
            });        
        }
        /**
         *页面数据加载成功
         */
        var flag_collect="";
        function handdle_func_succ(data){
            console.log(data);
            if(data.statu==0){
                flag_collect=1;
            }else{
                 flag_collect=0;
            }
            var shops=data.data.shop;
            if(shops!=null){
                locX=shops.locX;
                locY=shops.locY;
                var shopname=shops.shopName;//店铺名
                var shopImg=shops.logoImgPath;//店铺照片
                var openToEnd=shops.openTime+" - "+shops.closeTime;//店铺营业时间
                var shopAddress=shops.address;//店铺地址
                var phoneNo=shops.phoneNO;//电话号码
                var collectNum=shops.shopCollectCount;//收藏人数
                var viewNum=shops.viewCount;//浏览数
                var shopProductNum=shops.shopProductsCount;//商品数
                var shopIntroduce=shops.remark;//店铺介绍
                var shopProducts=data.data.productList;//店铺产品
                var dataStr="";//店铺产品数据列表
                var  auth=data.data.authImgs;//认证图片
                var isCollect=data.data.shop.isCollect;
                var isAvaliable=data.data.sellerFees.length;
                console.log(isCollect+"====");
                $(".s-showImg img").attr("src",shopImg);
                
                $(".shopDetail .shopD-bg").css("backgroundImage","url("+shopImg+")");
                $(".info-det .shop-name").html(shopname);
                $(".work-time").html(openToEnd);
                $(".address-detail-l").find(".address").html(shopAddress);
                $(".phoneNo").html(phoneNo);
                $(".num-collect .num-top").html(collectNum);
                $(".num-visit .num-top").html(viewNum);
                $(".num-goods .num-top").html(shopProductNum);
                $(".s-intro").html(shopIntroduce);
                $("title").html(shopname);
                $("#desc").attr("content",shopIntroduce);
                $(".mess-span").attr("href","sms:"+phoneNo);
                $(".tell-span").attr("href","tel:"+phoneNo);
                $(".shop-name .name").html(shopname);
                console.log($(".s-showImg img").css("width")+"---"+$(".s-showImg img").css("height"));
                var r_border="";
                if(shopImg!=null){
                    $(".info-img img").attr("src",shopImg);
                }else{
                    $(".info-img img").attr("src","./images/error.png");
                }
                var shopImgs=data.data.shopImgs;
                var shopImgLen=shopImgs.length;
                var shopImgsStr='';
                if(shopImgLen>0){
                    for(var i=0;i<shopImgLen;i++){
                        if(shopImgs[i].FULLPATH!=null&&i<5){
                            shopImgsStr+='<img src="'+shopImgs[i].FULLPATH+'" alt="">';            
                        }
                    }
                    $(".imgs-det").html(shopImgsStr);
                }
                //是否收藏的标志
                $(".collect-btn ").on("click",function(){
                    if(userId>0){
                        if(flag_collect==1){
                           requestData6=JSON.stringify({
                               "code":"cancelCollect",
                               "version":"1.0",
                               "data":{
                                   "shopIds":[shopId],
                                   "userId":userId
                               }
                           });
                            getData(url,requestData6,haddle_func_succ3,handdle_func_err,async,type); 
                        }else{
                             requestData1=JSON.stringify({
                                 "code":"userCollect",
                                 "version":"1.0",
                                 "data":{
                                     "shopId":shopId,
                                     "userId":userId
                                 }
                             });  getData(url,requestData1,handdle_func_succ1,handdle_func_err,async,type);
                        }
                    }else{
                        $(".zwl-zwl").fadeIn(1500);
                        $(".zwl-zwl").fadeOut(500);
                    }

                });
                //本店产品
                for(var i=0,len=shopProducts.length;i<len;i++){
                    var str="";
                    var wStr="";
                    var hStr="";
                    a(i);
                    function a(i){
                        var img=new Image();
                        var i=i;
                        img.src=shopProducts[i].mainImgPath;
                        if(shopProducts[i].mainImgPath==null||shopProducts[i].mainImgPath=="null"){
                            img.src=" ../images/error.png";
                        }else{
                            img.src=shopProducts[i].mainImgPath;
                        }
                        img.onload = function(){    
                            if((img.width/img.height)<1){
                                wStr="7.56rem";
                                hStr="auto";
                            }else{
                                wStr="auto";
                                hStr="7.56rem";
                            }
                            console.log(img.src);
                            
                        };    
                        
                    };
                    if(data.data.seller.isSellerAuth==0){
                        isauth='<span>(未认证)</span>';
                    }else{
                        isauth='<img src="./images/vip_icon.png" alt="">';
                    }  
                    dataStr+='<div data-proId="'+shopProducts[i].productId+'" class="zwl-noCertificate"><div class="goodNoCertificate"><img class="zwl-img" src="'+shopProducts[i].mainImgPath+'" alt=""><div class="zwl-shoppingDetail"><p class="zwl-p">'+shopProducts[i].productName+'</p><span class="shop1">'+shopProducts[i].productTypeName+'</span><span class="shopRe1">'+isauth+'</span><span class="span2"> <span class="money">'+shopProducts[i].saleprice+'元/</span><span class="cess">'+shopProducts[i].unit+'</span></span></div></div></div>';
                }
                $(".goods-lists").html(dataStr);
                $(".zwl-noCertificate").on("click",function(){
                    var productId=$(this).attr("data-proId");
                    location.href="./goodDetail.html?productId="+productId+"&userId="+userId;
                });
                
                //配送or支付
                if(isAvaliable>0){
                    var tagStr="";
                    var tag="";
                    if(data.data.tagServices){
                        for(var i=0;i<2;i++){
                            tagStr+='<img class="img1" src="'+data.data.tagServices[i].tagIconPath+'" alt=""><span class="span1">'+data.data.tagServices[i].userRemark+'</span>';    
                        }
                        $(".distri-pay").append(tagStr);
                        $(".unreg").addClass("hide").removeClass("show");  
                    }
                    
                }else{
                    $(".distri-pay").css("display","none");
                }
                
                
                $(".distri-pay").on("click",function(){
                    $(".zwl-pay").css("display","block");
                     $('html,body').css({"height":"100%","overflow":"hidden"});
                   requestDataTag=JSON.stringify({
                       "code":"getShopDetail",
                       "version":"1.0",
                       "data":{
                           "shopId":shopId,
                           "userId":userId
                       }
                   });                 getData(url,requestDataTag,call_func_tag,handdle_func_err,async,type);
                });
                function call_func_tag(data){
                    console.log(data);
                    var datas_tag=data.data;
                    var tagServices=datas_tag.tagServices.length;
                    var isAvaliableStr="";
                    
$("zwl-pay").css("backgroundImage","url("+datas_tag.shop.logoImgPath+")");
                    $(".zwl-shopname").html(datas_tag.shop.shopName);
                    for(var i=0;i<tagServices;i++){
                        isAvaliableStr+='<p class="zwl-lp"><img class="zwl-lpimg" src="'+datas_tag.tagServices[i].tagIconPath+'" alt=""><span class="zwl-lpdetail">'+datas_tag.tagServices[i].userRemark+'</span></p>';
                        $(".zwl-pp").html(isAvaliableStr);
                    } 
                    $(".zwl-closep").off("click");
                    $(".zwl-closep").on("click",function(){
                        $(".zwl-pay").css("display","none");
                        $('html,body').css({"height":"auto","overflow":"auto"});
                    });
                }
                //是否认证
                var AuthValue=data.data.seller.isSellerAuth;
                if(AuthValue==1){
                    var authStr="";
                    for(var i=0,len=auth.length;i<len;i++){
                        authStr+='<img src="'+auth[i].FULLPATH+'" class="img-center" alt="未认证">';        
                    }
                    $(".reg-imgs-det").html(authStr);
                }
                //是否登录
                if(userId>0){
                    //是否收藏
                     if(isCollect==0){
                            $(".collect-btn").find("img").attr("src","./images/collect02.png");
                            flag_collect=0; //未收藏
                      }else{
                           $(".collect-btn").find("img").attr("src","./images/collect01.png");
                          flag_collect=1;  //收藏
                      }
                }else{
                    $(".collect-btn").find("img").attr("src","./images/collect02.png");

                }
                
                /**
                 *点击地址，进入地图
                 */
                $(".address-detail").on("click",function(){
                    var addr=shopAddress.split(" ");
                    location.href="./map.html?locX="+locX+"&locY="+locY+"&address="+encodeURIComponent(addr);
                });
     
            }else{
                alert("数据异常");
            }
            //图片加载失败的时候，默认的图片
            $("img").on("error",function(){
                $(this).attr("src","./images/error.png");
            });
        }
        function handdle_func_err(msg){
            console.log(msg);
        }
    
        function haddle_func_succ3(data){
            console.log(data);
            if(data.statu==0){
                $(".collect-btn").find("img").attr("src","./images/collect02.png");
                flag_collect=0;
            }
        }
        function handdle_func_succ1(data){
            console.log(data);
            if(data.msg=="收藏成功"){
                $(".collect-btn").find("img").attr("src","./images/collect01.png");
                flag_collect=1;
            }else{
                $(".collect-btn").find("img").attr("src","./images/collect02.png");
                flag_collect=0;
            }
        }
    
//        wx.config({
//            debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
//            appId: 'wx131f440e1f2f5e4f', // 必填，公众号的唯一标识
//            timestamp: "", // 必填，生成签名的时间戳
//            nonceStr: '', // 必填，生成签名的随机串
//            signature: '',// 必填，签名，见附录1
//            jsApiList: ["onMenuShareAppMessage"] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
//        }); 
//        wx.ready(function(){
//            wx.onMenuShareAppMessage({
//                title: '测试一下', // 分享标题
//                desc: '哈哈哈哈', // 分享描述
//                link: location.href, // 分享链接
//                imgUrl:$(".s-showImg img").attr("src"), // 分享图标
//                type: '', // 分享类型,music、video或link，不填默认为link
//                dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
//                success: function () {
//                    alert("分享成功");
//                    // 用户确认分享后执行的回调函数
//                },
//                cancel: function () {
//                    alert("取消分享");
//                    // 用户取消分享后执行的回调函数
//                }
//            });
//        });
        
    
    
});
     /**
      *显示认证资料跟隐藏认证资料
      */   
     function toggleInfo(tagElement,displayStr,overflowStr){
        $(tagElement).on("click",function(){
              value="0"
              $("#shop-regi").css("display",displayStr);
              $("#content").css("display",displayStr);  
              $(".shop-register").attr("data-data",value);
        });  
     }
    toggleInfo(".shop-register","block","hidden");
    toggleInfo("#shop-regi","none","visible");
    /**
    *阻止事件冒泡
    */
    $("#content").on("scroll",function(e){
        stopPropagation(e);
    });
    function stopPropagation(e) {//阻止事件冒泡方法
        e = e || window.event;  
        if(e.stopPropagation) { //W3C阻止冒泡方法  
            e.stopPropagation();  
        } else {  
            e.cancelBubble = true; //IE阻止冒泡方法  
        }  
    }